package com.Questions.tanxin;


/**
 * 种花问题
 */
public class leetcode605 {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        if(flowerbed.length==1){
            if(flowerbed[0]==1&&n!=0){
                return false;
            }else if(flowerbed[0]==0&&n>1){
                return false;
            }else{
                return true;
            }
        }
        int max=0;
        for(int i=0;i<flowerbed.length;++i){
            if(i==0){
                if(flowerbed[i]==0&&flowerbed[i+1]==0){
                    flowerbed[i]=1;
                    max++;
                }
            }else if(i==flowerbed.length-1){
                if(flowerbed[i]==0&&flowerbed[i-1]==0){
                    flowerbed[i]=1;
                    max++;
                }
            }else{
                if(flowerbed[i-1]==0&&flowerbed[i]==0&&flowerbed[i+1]==0){
                    max++;
                    flowerbed[i]=1;
                }
            }
        }
        return max>=n;
    }
}
